package com.insigma.business.qrcode.notice.service.impl;

import com.insigma.business.common.utils.ToolsHelper;
import com.insigma.business.qrcode.common.dao.SoldierBasicInfoBDao;
import com.insigma.business.qrcode.common.service.SequenceGenerator;
import com.insigma.business.qrcode.common.template.area.BaseProviderImpl;
import com.insigma.business.qrcode.common.template.area.ScenarioCodeEnum;
import com.insigma.business.qrcode.common.template.area.ServiceCallback;
import com.insigma.business.qrcode.common.util.BizCheckUtil;
import com.insigma.business.qrcode.common.util.ResponseUtils;
import com.insigma.business.qrcode.common.vo.BaseResponse;
import com.insigma.business.qrcode.notice.dao.NoticeAnnouncementDAO;
import com.insigma.business.qrcode.notice.dto.NoticeAnnouncementDTO;
import com.insigma.business.qrcode.notice.entity.NoticeAnnouncementEntity;
import com.insigma.business.qrcode.notice.entity.NoticeFileEntity;
import com.insigma.business.qrcode.notice.service.NoticeAnnouncementService;
import com.insigma.business.qrcode.soldier.entity.SoldierApplyInfoDO;
import com.insigma.business.qrcode.soldier.service.SoldierApplyInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Slf4j
@Service("noticeAnnouncementService")
public class NoticeAnnouncementServiceImpl extends BaseProviderImpl implements NoticeAnnouncementService {

    @Resource
    private SequenceGenerator sequenceGenerator;

    @Resource
    private NoticeAnnouncementDAO naDAO;

    @Resource
    private SoldierBasicInfoBDao soldierBasicInfoBDao;

    @Resource
    SoldierApplyInfoService soldierApplyInfoService;


    @Override
    public BaseResponse<List<NoticeAnnouncementDTO>> queryAll(NoticeAnnouncementDTO requestDTO) throws Exception {
        final BaseResponse<List<NoticeAnnouncementDTO>> baseResponse = new BaseResponse<>();
        serviceTemplate.execute(baseResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotBlank(requestDTO.getNaType(),"必要参数不能为空");
                /*if(requestDTO.getNaType().equals("NA01")){
                    BizCheckUtil.checkNotBlank(requestDTO.getSoldierId(),"用户ID不能为空");
                }*/
            }

            @Override
            public void executeService() {
                NoticeAnnouncementEntity queryEntity = new NoticeAnnouncementEntity();
                //naType 值为“NA01”表示查询通知公告
                /*if(requestDTO.getNaType().equals("NA01")){
                    String areaCode = naDAO.queryAdmDivCode(requestDTO.getSoldierId());
                    if(StringUtils.isEmpty(areaCode)){
                        BizCheckUtil.checkNotBlank(requestDTO.getNaType(),"用户所属地区为空");
                    }
                    queryEntity.setAreaCode(areaCode);
                }*/
                queryEntity.setNaType(requestDTO.getNaType());
                List<NoticeAnnouncementEntity> list = naDAO.queryAll(queryEntity);
                List<NoticeAnnouncementDTO> naDTOList = ToolsHelper.copyListProperties(list, NoticeAnnouncementDTO::new);
                for (int i = 0; i < naDTOList.size(); i++) {
                    List<NoticeFileEntity> fileList = naDAO.queryNaFile(naDTOList.get(i).getId());
                    naDTOList.get(i).setFileList(fileList);
                }
                ResponseUtils.setupSuccessResponse(baseResponse,naDTOList);
            }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.CODE_ON_NOTICE_ANNOUNCEMENT_QUERY_LIST;
            }
        });
        return baseResponse;
    }


}
